//index.js
//获取应用实例
var util = require('../../../utils/util.js')
const app = getApp()
var _this
Page({
  data: {
    src_top: '../../resources/index_01.png',
    src_01: '../../resources/fenpei.png',
    src_02: '../../resources/xinnian.png',
    userInfo: {},
    unAuthorized:false,
    num_01: 1231231,
    percent_01: 68,
    num_02: 1231231,
    percent_02: 74
  },
  //事件处理函数
  bindViewTap: function() {
    wx.navigateTo({
      url: '../logs/logs'
    })
  },
  goEditPhoneNumber: function() {
    wx.navigateTo({
      url: '../phoneAdd/phoneAdd'
    })
  },
  getPhoneNumber(e) {
    console.log(e.detail.errMsg)
    console.log(e.detail.iv)
    console.log(e.detail.encryptedData)
    _this.handleGetPhone(e.detail.iv, e.detail.encryptedData)
  },
  authorizeFinished: (e) => {
    _this.setData({
      unAuthorized:app.globalData.unAuthorized
    })
    console.log(app.globalData.userInfo)
    _this.authrizeRefresh()
  },
  authrizeRefresh: () => {
    if (app.globalData.userInfo) {
      _this.setData({
        unAuthorized: false
      })
      wx.setNavigationBarTitle({
        title: '手机号码',
      })
    } else {
      _this.setData({
        unAuthorized: true
      })
      wx.setNavigationBarTitle({
        title: '手机授权',
      })
    }
  },
  handleGetPhone: (iv, encryptedData) => {
    util.getPhoneNumber(_this.requestDidResponse, _this.requestDidFaild, iv, encryptedData)
  },
  requestDidResponse: (res) => {
    console.log('did receive response: ' + res)
    if (res.status == '200') {
      wx.navigateTo({
        url: '../../modules/peopleAssigned/infoGender/infoGender'
      })
    }
  },
  requestDidFaild: (res) => {

  },
  onLoad: function () {
    var ticket = wx.getStorageSync('ticket'); //获取本地缓存中的userIdEnc //用户唯一识别码
    var loginUserInfo = wx.getStorageSync('userInfo');//获取本地缓存中的loginDevice
    console.log(ticket)
    console.log(loginUserInfo)
    _this = this
    _this.authrizeRefresh()
  }
})
